<!DOCTYPE html>
<html lang="en" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common :: header('权限分配')"/>
    <style>
        .layui-form-label{
            width:80px;
        }
    </style>
</head>
<body>
<form action="" class="layui-form">
    <div class="mainBox">
        <div class="main-container">

            <div class="layui-form-item">
                <label class="layui-form-label">权限分配</label>
                <div class="layui-input-block">
                    <div id="tree-showCheckbox"></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="treeList" id="treeList" th:value="${treeList}">
                    <button class="pear-btn pear-btn-primary" lay-submit lay-filter="formDemo">保存</button>
                </div>
            </div>
        </div>
    </div>
</form>
</body>

<th:block th:include="common :: footer"/>
<script th:inline="javascript">
    layui.use(['form', 'jquery', 'tree','layer'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let layer = layui.layer;
        var tree = layui.tree;
        //获取当前所有菜单
        //var data = [{title:'早餐',id:1,children:[{title:'拌粉',id:5},{title:'蒸饺',id:6},{title:'豆浆',id:7}]},{title:'午餐',id:2,checked:true,children:[{title:'藜蒿炒腊肉',id:8},{title:'西湖醋鱼',id:9},{title:'小白菜',id:10},{title:'海带排骨汤',id:11}]},{title:'晚餐',id:3,children:[{title:'红烧肉',id:12,fixed:true},{title:'番茄炒蛋',id:13}]},{title:'夜宵',id:4,children:[{title:'小龙虾',id:14,checked:true},{title:'香辣蟹',id:15,disabled:true},{title:'烤鱿鱼',id:16}]}];
        var treeList = $("#treeList").val();
        var data = JSON.parse(treeList);
       // console.log(treeList);
          // 渲染
          tree.render({
            elem: '#tree-showCheckbox',
            data: data,
            showCheckbox: true,
            //edit: ['add', 'update', 'del'] // 开启节点的右侧操作图标
          });

        form.on('submit(formDemo)', function (data,tree) {
            var checkedData = tree.getChecked('tree-showCheckbox');
            console.log("checkData:",checkedData);
            //layer.alert(JSON.stringify(checkedData), {shade:0});
            debugger;
            return false;
            $.ajax({
                url: '/admin/role/addRbac',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("slide-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })

</script>
</html>